Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add owner fallback #49827

Open
wants to merge 1 commit into
base: stable29
Choose a base branch
from

Conversation

miaulalala
Copy link
Contributor

@miaulalala miaulalala commented Dec 12, 2024

Signed-off-by: Anna Larch [email protected]

  • Resolves: #

Summary

TODO

  • ...

Checklist

@miaulalala miaulalala self-assigned this Dec 12, 2024
@miaulalala miaulalala added the 2. developing Work in progress label Dec 12, 2024
@miaulalala
Copy link
Contributor Author

/backport to stable28

@miaulalala miaulalala marked this pull request as ready for review December 16, 2024 15:29
Signed-off-by: Anna Larch <[email protected]>
@miaulalala miaulalala force-pushed the fix/noid/empty-path-for-files-versions branch from 2ebc7dd to a39a5c6 Compare December 17, 2024 13:54
@solracsf
Copy link
Member

solracsf commented Dec 18, 2024

DRY 🙈

/**
 * Retrieve the path relative to the current user root folder.
 * If no user is connected, try to use the node's owner.
 */
private function getPathForNode(Node $node): ?string {
	$user = $this->userSession->getUser()?->getUID();
	if ($user !== null) {
		return $this->getRelativePathForUser($user, $node);
	}

	$owner = $node->getOwner()?->getUid();
	if ($owner !== null) {
		return $this->getRelativePathForUser($owner, $node);
	}

	// Attempt to extract the owner from the path
	$parts = explode('/', $node->getPath(), 4);
	$owner = (count($parts) === 4) ? $parts[1] : null;
	if ($owner !== null) {
		return $this->getRelativePathForUser($owner, $node);
	}

	return null;
}

/**
 * Get the relative path for a given user and node.
 */
private function getRelativePathForUser(string $user, Node $node): ?string {
	return $this->rootFolder
		->getUserFolder($user)
		->getRelativePath($node->getPath()) ?: null;
}

Copy link
Contributor

@artonge artonge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the difference is with the original

@SystemKeeper
Copy link
Contributor

Not sure what the difference is with the original

In the original version we only try to extract the owner from the path, when we are unable to get the owner from the node.

Now we try to get the owner from the path as a fallback in all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress
Projects
Status: 🏗️ In progress
Development

Successfully merging this pull request may close these issues.

4 participants